package com.boilerCloud.dao.device;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.boilerCloud.dao.BaseDao;
import com.boilerCloud.dto.HzlqswPage;
import com.boilerCloud.dto.device.ModelCode;
import com.boilerCloud.util.StringUtil;
@Repository
public class ModeCodeDao extends BaseDao{

	public void qryList(ModelCode model, HzlqswPage<ModelCode> page) throws Exception {
		String countsql = "select count(*) from d_model_code a "
		+ " where a.is_delete='n' ";
	
		String listSql = "select a.id,a.code,a.create_time "
			+ " from d_model_code a "
			+ " where a.is_delete='n' ";
		List<Object> params= new ArrayList<Object>();
		if(!StringUtil.isEmpty(model.getCode())){
			countsql += " and a.code like ?";
			listSql += " and a.code like ?";
			params.add("%" + model.getCode() +"%");
		}
		
		listSql += " order by id desc ";
		this.queryListByPage(countsql, params, listSql, params, page, ModelCode.class);
			
	}

	public void edit(ModelCode model) {
		String sql = "update d_model_code set code =?, modify_time = now() where id = ?";
		this.jdbcTemplate.update(sql,model.getCode(),model.getId());
		
	}

	public void del(int id) {
		String sql = "update d_model_code set is_delete ='y' where id = ?";
		this.jdbcTemplate.update(sql,id);
		
	}

	public void save(ModelCode model) {
		String sql = "insert into d_model_code(code,create_time,modify_time,is_delete) values(?,now(),now(),'n')";
		this.jdbcTemplate.update(sql,model.getCode());
		
	}

	public List<ModelCode> getModelCodeList(ModelCode code) throws Exception {
		String sql = "select id,code from d_model_code where is_delete = 'n'";
		return this.queryForList(sql, ModelCode.class);
	}

	public ModelCode getModelCode(int id)throws Exception {
		String sql = "select * from d_model_code where id=? limit 1";
		return this.queryForObject(sql,ModelCode.class,id);
	}

}
